/**
 * @Title: Test.java
 * @Package tbg 
 * @Description: TODO
 * @author tbc
 * @date 2016年6月7日 下午11:50:05
 * @version
 */
package tbg;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * <p>
 * 构造： XSSFWorkbook、Workbook ，参数：输入流
 * </p>
 * <p>
 * Cell Type : 相关常量定义位于接口 {@link org.apache.poi.ss.usermodel.Cell}
 * <li>Cell#CELL_TYPE_NUMERIC - 0
 * <li>Cell#CELL_TYPE_STRING - 1
 * <li>Cell#CELL_TYPE_FORMULA - 2
 * <li>Cell#CELL_TYPE_BLANK - 3
 * <li>Cell#CELL_TYPE_BOOLEAN - 4
 * <li>Cell#CELL_TYPE_ERROR - 5
 * </p>
 * <p>
 * 获取CELL的值 <br>
 * 
 * </p>
 * 
 * @author tbc
 * @version 1.0 create:{2016年6月7日 下午11:50:05}
 * 
 */
public class PoiDemo {
	private static Logger log = LoggerFactory.getLogger(PoiDemo.class);

	public static void main(String[] args) {
		File file = new File("h:\\Users\\tbc\\Desktop\\长城1605-出口.xlsx");

		InputStream in = null;
		XSSFWorkbook excelBook = null;
		try {
			in = new FileInputStream(file);
			excelBook = new XSSFWorkbook(in);
		} catch (FileNotFoundException e) {
			log.error("read file error : {}", e.getMessage());
		} catch (IOException e) {
			log.error("create XSSFWorkbook error : {}", e.getMessage());
		}

		XSSFSheet sheet1 = excelBook.getSheet("综合发车");
		int lastRowNum = sheet1.getLastRowNum();
		// 注，lastRowNum = _rows.lastKey();
		// public int getLastRowNum() {
		// return _rows.size() == 0 ? 0 : _rows.lastKey();
		// }

		System.out.println(lastRowNum);

		XSSFRow row1 = sheet1.getRow(11);
		int lastCellNum = row1.getLastCellNum();
		log.debug("row1 lastCellNum : {}", lastCellNum);

		XSSFCell cel = row1.getCell(4);
		XSSFCell cell = row1.getCell(2);
		log.debug("cell type : {}, value : {}", cel.getCellType(), cel.getRawValue());
		log.debug("cell type : {}, value : {}", cell.getCellType(), cell.getStringCellValue());

		XSSFRow row = sheet1.getRow(1);
		System.out.println(row.getCell(4).getStringCellValue());
		System.out.println(row.getCell(6).getRawValue());

	}
}
